﻿(function ($) {
    $.ptslib = { toId: function (jsonReaderId) { return typeof jsonReaderId == 'string' ? jsonReaderId : ''; },
        dlgError: null, gridLoadError: null, selectPerson: null, selectPersonChange: null,       
        resizeCenterPane: null, loading: $('<img src="/../Content/themes/base/images/ui-anim_basic_16x16.gif" alt="Loading..." class="loading">')
    };
})(jQuery);


function aspJsonDate(jsonDate) {
    if (jsonDate)
        return new Date(parseInt(jsonDate.substr(6)));
    return;
}

function gridDateTimeConvert(cellValue, options, rowObject) {

    if (cellValue) {
        var d = aspJsonDate(cellValue);
        //(format, date, newformat, opts
        return $.fmatter.util.DateFormat('', d, options.colModel.newformat, $.extend({}, $.jgrid.formatter.date, options));
    }
    else
        return '';
}

function imageFormat(cellvalue, options, rowObject) {
    return '<img src="' + cellvalue.split('~').slice(1) + '" class="formatImg" />';
}

function imageUnFormat(cellvalue, options, cell) {
    return $('img', cell).attr('src');
}

jQuery('.numeric').live('keydown', function (event) {
    //this.value = this.value.replace(/[^0-9\.]/g, '');
    // Allow: backspace, delete, tab, escape, and enter
    if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 ||
    // Allow: Ctrl+A
            (event.keyCode == 65 && event.ctrlKey === true) ||
    // Allow: home, end, left, right
            (event.keyCode >= 35 && event.keyCode <= 39)) {
        // let it happen, don't do anything
        return;
    }
    else {
        // Ensure that it is a number and stop the keypress
        if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) {
            event.preventDefault();
        }
    }

});

var gdatePick = function (elem) {
    jQuery(elem).datepicker({
        onSelect: function (dateText, inst) {
            //TODO: do filter
        }
    });
}

function pad(num, places, c) {
    if (!c)
        c = "0";
    var zero = places - num.toString().length + 1;
    return Array(+(zero > 0 && zero)).join(c) + num;
}

$(function () {
    $('#Displayname').hover(function () {
        $(this).addClass('display-hover');
        $('.dropdown-menu', this).stop(true, true).slideDown(200);

    }, function () {
        $(this).removeClass('display-hover');
        $('.dropdown-menu', this).stop(true, true).delay(3000).slideUp(200);
    });
    $('#menu li a').each(function () {
        var a = $(this);
        if (window.location.pathname == a.attr('href')) {
            a.parent().addClass('selected');
            return false;
        }
    });
});